<?php

namespace app\special\controller;

use app\common\controller\Api;
use app\common\logic\Common;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
use PhpOffice\PhpSpreadsheet\Style\Border;
use PhpOffice\PhpSpreadsheet\Style\Fill;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use app\special\service\Excel;


class Index extends Api
{
    protected $noNeedRight = '*';
   /* protected $noNeedLogin = '*';

   /* protected $layout = '';*/
     /*适用年龄*/
    public function agelist()
    {
        $param = [
            'customer_id' => 259,

        ];
        $list = Common::getBiaozhunList($param);
        $jsonList = json_encode($list);
        // 返回 JSON 数据给前端
        return $jsonList;
    }


    public function zteyiquerylist()
    {
        $param = [
            'customer_id' => 259,
        ];
        $paramsFromRequest = $this->request->param();
        $mergedParams = array_merge($param, $paramsFromRequest);
        $url = "zteyiquerylist";
        $list = Common::getBiaozhunLists($mergedParams, $url);
        $jsonList = json_encode($list);
        // 返回 JSON 数据给前端1
        return $jsonList;
    }

    public function companylist()
    {
        $param = [
            'customer_id' => 259,
        ];
        $paramsFromRequest = $this->request->param();
        $mergedParams = array_merge($param, $paramsFromRequest);
        $url = "companylist";
        $list = Common::getBiaozhunLists($mergedParams, $url);
        $jsonList = json_encode($list);
        // 返回 JSON 数据给前端1
        return $jsonList;
    }


    public function zteyiquerydetail()
    {
        $data = $this->request->param();
        $param = [
            'customer_id' => 259,
            'itemid' => $data['itemid']
        ];
        $url = "zteyiquerydetail";
        $list = Common::getBiaozhunLists($param, $url);
        $jsonList = json_encode($list);
        // 返回 JSON 数据给前端1
        return $jsonList;
    }

    public function zteyiqueryexport()
    {
        $param = [
            'customer_id' => 259,
        ];
        $url = "zteyiquerylist";
        $list=[];
        $data= $this->request->param();

        /*测试数据*/
        $headers = $data['headers'];


        $headers = Excel::matching($headers);
        if (isset($data['data'])&& !empty($data['data'])){
            $list = $data['data'];
            $spreadsheet= Excel::mystyle($headers,$list);
        }else{

            $mergedParams = array_merge($param, $data['condition']);
            /* var_dump($mergedParams);
             die;*/
            $list = Common::getBiaozhunLists($mergedParams, $url);

            $spreadsheet= Excel::mystyle($headers,$list['data']['data']);
        }
        $timestamp = time();
        $excelurl= "/excel/".$timestamp."teyi";
        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment;filename="' . '123' . '.xlsx"');
        header('Cache-Control: max-age=0');
        $writer = new Xlsx($spreadsheet);
        $writer->save('php://output');
        //删除清空：
     $spreadsheet->disconnectWorksheets();
        exit();
    }

    public function nourishment()
    {
        $data = $this->request->param();
        $param = [
            'customer_id' => 259,
        /*    'itemid' => $data['itemid']*/
        ];
        $url = "zteyidatalist";
        $list = Common::getBiaozhunLists($param, $url);
        $jsonList = json_encode($list);
        // 返回 JSON 数据给前端1
        return $jsonList;
    }
   /*营业成分分类*/
    public function getnourishment()
    {
        $data = $this->request->param();
        $param = [
            'customer_id' => 259,
            /*    'itemid' => $data['itemid']*/
        ];
        $url = "zteyidatalists";
        $list = Common::getBiaozhunLists($param, $url);
        $jsonList = json_encode($list);
        // 返回 JSON 数据给前端1
        return $jsonList;
    }

        public function productcategorytype()
    {
        $param = [
            'customer_id' => 259,
        ];
        $paramsFromRequest = $this->request->param();
        $mergedParams = array_merge($param, $paramsFromRequest);
        $url = "productcategorytype";
        $list = Common::getBiaozhunLists($mergedParams, $url);
        $jsonList = json_encode($list);
        // 返回 JSON 数据给前端1
        return $jsonList;
    }

    public function commoditylist()
    {
        $param = [
            'customer_id' => 259,
        ];
        $paramsFromRequest = $this->request->param();
        $mergedParams = array_merge($param, $paramsFromRequest);
        $url = "commoditylist";
        $list = Common::getBiaozhunLists($mergedParams, $url);
        $jsonList = json_encode($list);
        // 返回 JSON 数据给前端1
        return $jsonList;
    }


    public function enterpriselist()
    {
        $param = [
            'customer_id' => 259,
        ];
        $paramsFromRequest = $this->request->param();
        $mergedParams = array_merge($param, $paramsFromRequest);
        $url = "enterpriselist";
        $list = Common::getBiaozhunLists($mergedParams, $url);
        $jsonList = json_encode($list);
        // 返回 JSON 数据给前端1
        return $jsonList;
    }



}
